home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Franz PD / Franz PD Disk #005 (19xx)(Amiga User Group Deutschland e.V.).zip / Franz PD Disk #005 (19xx)(Amiga User Group Deutschland e.V.).adf / FixWB / fixwb.c < prev    next >
C/C++ Source or Header  |  1986-10-22  |  4KB  |  146 lines

  1. /*  :ts=8 bk=0
  2.  *
  3.  * fixwb.c:    A program to fix the WorkBench backdrop window into place,
  4.  *        by turning it into a SMART_REFRESH window.  Also will load
  5.  *        an IFF image into the window, assuming I can figure out the
  6.  *        IFF spec.
  7.  *
  8.  * Sigh.  As it turns out, the WorkBench program makes this effort
  9.  * impossible since it clears the backdrop window everytime something new
  10.  * happens with the disk icons.
  11.  *
  12.  * Leo L. Schwab        8703.10        (415)-456-6565
  13.  */
  14.  
  15. #include <exec/types.h>
  16. #include <intuition/intuition.h>
  17.  
  18. /*  Only the full-screen WorkBench window has these two flags set.  */
  19. #define    WBACK        (WBENCHWINDOW | BACKDROP)
  20.  
  21. extern void    *OpenLibrary(), *OpenWindow(), *CreateBehindLayer();
  22.  
  23. struct NewWindow windef = {
  24.     0, 30, 200, 10,
  25.     -1, -1,
  26.     NULL,
  27.     WINDOWDRAG | WINDOWDEPTH | SMART_REFRESH | ACTIVATE,
  28.     NULL, NULL,
  29.     (UBYTE *) "Computing...",
  30.     NULL, NULL,
  31.     0, 0, 0, 0,
  32.     WBENCHSCREEN
  33. };
  34.  
  35. struct Window    *win;
  36. void        *IntuitionBase, *GfxBase, *LayersBase;
  37.  
  38.  
  39. main ()
  40. {
  41.     struct Screen *wbs;
  42.     struct Layer_Info *li;
  43.     struct Layer *wbl;
  44.     struct Window *chk, *wbw = 0;
  45.     long top, left, wide, high;
  46.     long flags;
  47.  
  48.     openstuff ();
  49.     wbs = win -> WScreen;    /*  Get pointer to WorkBench screen  */
  50.     li = &wbs -> LayerInfo;
  51.  
  52.     for (chk = wbs -> FirstWindow; chk; chk = chk -> NextWindow) {
  53.         flags = chk -> Flags;
  54.         if ((flags & WBACK) == WBACK) {
  55.             wbw = chk;
  56.             break;
  57.         }
  58.     }
  59.     if (!wbw)
  60.         die ("WorkBench not loaded.");
  61.     if ((flags & REFRESHBITS) == SMART_REFRESH)
  62.         die ("WorkBench already fixed.");
  63.     top    = wbw -> TopEdge;
  64.     left    = wbw -> LeftEdge;
  65.     wide    = wbw -> Width;
  66.     high    = wbw -> Height;
  67.  
  68.     wbl = wbw -> RPort -> Layer;    /*  Get the layer pointer  */
  69.  
  70.     /*
  71.      * At this point, we are about to perform what is probably
  72.      * tantamount to rape to the system.  Therefore, I'm Forbid()ing
  73.      * anything else from running so as to prevent a major collapse.
  74.      *
  75.      * First, we stop everyone else.  Then, we un-backdrop the layer
  76.      * so we can depth-arrange it.  We then bring it to the front,
  77.      * forcing the layers library to save the state of everything else.
  78.      * Then we change the identity of the layer from SIMPLE to SMART.
  79.      * Then we depth-arrange it to the back again.  This will make all
  80.      * previous layers visible, and cause the library to create all the
  81.      * necssary ClipRects and backup bitmaps for us.  Then we re-set
  82.      * the backdrop bit, anchoring the window into place.
  83.      */
  84.  
  85.     Forbid ();
  86.     wbl -> Flags &= ~LAYERBACKDROP;
  87.     UpfrontLayer (li, wbl);
  88.     wbl -> Flags = wbl -> Flags & ~LAYERSIMPLE | LAYERSMART;
  89.     BehindLayer (li, wbl);
  90.     wbl -> Flags |= LAYERBACKDROP;
  91.  
  92.     /*  Correct Intuition's ideas about the window.  */
  93.     wbw -> Flags = flags & ~SIMPLE_REFRESH | SMART_REFRESH;
  94.  
  95.     Permit ();    /*  That should do it  */
  96.  
  97.     /*  Do things in the newly fixed WorkBench  */
  98.     SetAPen (wbw -> RPort, 1L);
  99.     Move (wbw -> RPort, 0L, 0L);
  100.     Draw (wbw -> RPort, wide-1, high-1);
  101.     Move (wbw -> RPort, 0L, high-1);
  102.     Draw (wbw -> RPort, wide-1, 0L);
  103.     /*
  104.      * If you want to watch the Mask "bug" at work, uncomment this next
  105.      * line of code.  Move window on and off disk icons and watch the
  106.      * results.
  107.      *
  108.      * wbw -> RPort -> Mask = 1;
  109.      */
  110.     closestuff ();
  111. }
  112.  
  113.  
  114. openstuff ()
  115. {
  116.     if (!(IntuitionBase = OpenLibrary ("intuition.library", 0L)))
  117.         die ("Intuition unavailable, use logic.");
  118.  
  119.     if (!(GfxBase = OpenLibrary ("graphics.library", 0L)))
  120.         die ("Art shop closed.");
  121.  
  122.     if (!(LayersBase = OpenLibrary ("layers.library", 0L)))
  123.         die ("Nothing laying around.");
  124.  
  125.     if (!(win = OpenWindow (&windef)))
  126.         die ("Window painted shut.");
  127. }
  128.  
  129. closestuff ()
  130. {
  131.     if (win)        CloseWindow (win);
  132.     if (LayersBase)        CloseLibrary (LayersBase);
  133.     if (GfxBase)        CloseLibrary (GfxBase);
  134.     if (IntuitionBase)    CloseLibrary (IntuitionBase);
  135. }
  136.  
  137. die (str)
  138. char *str;
  139. {
  140.     puts (str);
  141.     closestuff ();
  142.     exit (10);
  143. }
  144.  
  145.  
  146.